package com.feihong.txgw.ui.activity.setting;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.feihong.txgw.R;
import com.feihong.txgw.message.LoginMessage;
import com.feihong.txgw.model.bean.suggest.Suggestmodel;
import com.feihong.txgw.ui.activity.base.BaseActivity;
import com.feihong.txgw.utils.ToastUtils;
import com.feihong.txgw.utils.helper.RxHelper;
import com.feihong.txgw.utils.manage.RetrofitManager;

import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class SuggestActivity extends BaseActivity {


    @BindView(R.id.et_input_text)
    EditText etInput;

    private Disposable mDisposable;

    @Override
    public void setTheme() {

    }

    @Override
    public int setLayoutID() {
        return R.layout.setting_suggest;
    }


    @Override
    public void initView(Bundle savedInstanceState) {
        setBackButtonFinish();
        setPageTitle("意见反馈");
    }

    @Override
    public void bindData() {

    }

    @Override
    public void onUserLogin(LoginMessage loginMessage) {

    }

    public void suggestSubmit(View view) {

        String edinput = etInput.getText().toString();

        if (!TextUtils.isEmpty(edinput)) {
            RetrofitManager.getInstance().submitSuggest(edinput, "", "1")
                    .compose(RxHelper.<Suggestmodel>rxSchedulerHelper())
                    .subscribe(new Observer<Suggestmodel>() {
                        @Override
                        public void onSubscribe(Disposable d) {
                            if (mDisposable != null) {
                                mDisposable.dispose();
                            }
                            mDisposable = d;
                        }

                        @Override
                        public void onNext(Suggestmodel result) {
                            if (activityIsDestory()) {
                                return;
                            }
                            if (result.getCode() != 200) {
                            } else {
                                showSystemToast("反馈成功！");
                                finish();
                            }
                        }

                        @Override
                        public void onError(Throwable e) {
                            if (activityIsDestory()) {
                                return;
                            }
                            ToastUtils.getInstance().showShortToast("请检查您的网络是否正常");
                        }

                        @Override
                        public void onComplete() {

                        }
                    });
        } else {
            ToastUtils.getInstance().showShortToast("您还没输入您的宝贵意见");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mDisposable != null){
            mDisposable.dispose();
        }
    }
}
